<template>
  <el-card class="box-card">
    <div slot="header" class="clearfix">
      <span>确认收货地址</span>
      <el-button style="float: right; padding: 3px 0" type="text" @click="goAdress">管理收货地址</el-button>
    </div>
    <div v-for="(item, index) in addressList" :key="index" class="text item">
      <div class="address-item">
        <i class="el-icon-location-outline"></i>
        <div class="address-item-jsz">寄送至</div>
        <el-radio v-model="radio" :label="item.id" class="address-item-text">
          {{item.province}} {{item.city}} {{item.region}} {{item.street}} {{item.detailed}} （{{item.consignee}} 收）{{item.phone}}
        </el-radio>
      </div>
    </div>
  </el-card>
</template>

<script>
export default {
  data() {
    return {
      radio: 1,
      addressList: []
    };
  },
  watch: {
    radio(val) {
      var defultItem = this.addressList.find(item => {
        return item.id == val;
      });
      this.$bus.emit('buy-info-address-change', defultItem);
    }
  },
  methods: {
    goAdress() {
      this.$router.push({
        name: 'address'
      });
    }
  },
  async activated() {
    var { data, code } = await this.$http.get("/index.php/getAddressList");
    this.addressList = data;
    var defultItem = this.addressList.find(item => {
      return item.isDefault == 1;
    });
    this.radio = defultItem.id;
    this.$bus.emit('buy-info-address-change', defultItem);
  }
};
</script>

<style lang="less" scoped>
.box-card {
  margin-top: 30px;
}
.address-item {
  display: flex;
  height: 50px;
  align-items: center;
  padding-left: 20px;

  &:hover {
    background: #398ade;
    color: #fff;
    .address-item-text {
      color: #fff;
    }
  }

  .address-item-jsz {
    margin-right: 20px;
  }
}
  // .text {
  //   font-size: 14px;
  // }

  // .item {
  //   margin-bottom: 18px;
  // }

  // .clearfix:before,
  // .clearfix:after {
  //   display: table;
  //   content: "";
  // }
  // .clearfix:after {
  //   clear: both;
  // }

  // .box-card {
  //   width: 480px;
  // }
</style>